package edu.ccut.saturn.basecomponent.database.impl;

import edu.ccut.saturn.basecomponent.database.IDeleteSQLBuilder;
import edu.ccut.saturn.basecomponent.database.ISaturnSQL;
import edu.ccut.saturn.basecomponent.database.util.SaturnDataUtil;
import edu.ccut.saturn.component.IDataInfo;
import edu.ccut.saturn.component.SaturnDataManager;

public abstract class AbstractDeleteSQLBuilder extends AbstractSQLBuilder implements IDeleteSQLBuilder {

	public ISaturnSQL build(String fullKey, String condition) throws Exception {
		IDataInfo dataInfo = SaturnDataManager.getInstance().getSaturnDataInfo(
				fullKey);
		StringBuffer sql = new StringBuffer();
		String tableName = SaturnDataUtil.getTableName(dataInfo);
		sql.append("DELETE FROM ").append(tableName).append(" ").append(
				condition);
		SaturnSQL saturnsql = new SaturnSQL();
		saturnsql.setSql(sql.toString());
		saturnsql.setDBtype(this.getDatabaseType());
		saturnsql.setSaturnData(null);
		saturnsql.setSaturnDataFullKey(dataInfo.getDataFullKey());
		saturnsql.setOperationType(this.getOperationType());
		
		return saturnsql;
	}

}
